package cate.game.play.skill.passive.hero;

import cate.common.util.XT;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.proce.action.ctx.SkillActionCtx;
import cate.game.play.proce.action.ctx.TimeActionCtx;
import cate.game.play.proce.move.AppendMove;
import cate.game.play.proce.move.MoveCtx;
import cate.game.play.skill.Skill;
import cate.game.play.skill.passive.PassiveHandler;

/**
 * 受到攻击时，100%使用物理攻击反击造成120%物理伤害
 */
public class 对决反击PH extends PassiveHandler {

	private int 概率;

	private int 反击技能;

	//概率=6000&反击技能=？？
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		概率 = args.getInt("概率", 0);
		反击技能 = args.getInt("反击技能", 0);
	}

	private boolean needStrike = false;

	@Override
	public void afterSufferOneAttack(SkillActionCtx action, long totalDamage, boolean strike) {
		if (needStrike) {
			return;
		}
		if (action.getMove().isAppend()) {
			return;
		}
		if (!XT.chance(概率)) {
			return;
		}
		needStrike = true;
	}

	@Override
	public void onMoveDone(MoveCtx move, TimeActionCtx action) {
		if (needStrike) {
			Skill appendSkill = move.getCfg().skill.buildById(skill.owner, 反击技能);
			appendSkill.param.addAppointTarget(move.getActor());
			AppendMove append = new AppendMove(skill.owner, appendSkill);
			move.getTurn().addAppend(append);
			needStrike = false;
		}
	}
}
